package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.system.domain.SysOfConfig;
import com.sale.system.service.ISysOfConfigService;
import com.sale.common.core.web.controller.BaseController;
import com.sale.system.domain.dto.OfConfigDto;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 编码生成变量控制层
 * @Param
 * @return
 * @Date 22-11-16
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ofconfig")
public class SysOfConfigController extends BaseController {

    private final ISysOfConfigService sysOfConfigService;


    /**
     * 获取编码配置
     */
    //@SaCheckPermission("system:ofConfig:list")
    @GetMapping("/list")
    public OfConfigDto list()
    {
        return sysOfConfigService.selectOfConfigList();
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("system:ofConfig:query")
    @GetMapping(value = "/{configId}")
    public R<Map<String, Object>> getInfo(@PathVariable long configId)
    {
        Map<String, Object> ajax = new HashMap<>();
        ajax.put("detailed", sysOfConfigService.selectOfConfigById(configId));
        return R.ok(ajax);
    }

    /**
     * 新增编码变量
     */
    //@SaCheckPermission("system:ofConfig:add")
    @Log(title = "变量新增", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysOfConfig sysOfConfig) throws Exception {
        return toAjax(sysOfConfigService.sysOfConfigAdd(sysOfConfig));
    }

    /**
     * 删除编码
     */
    //@SaCheckPermission("system:ofConfig:remove")
    @Log(title = "配置变量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configId}")
    public R<Void> remove(@PathVariable("configId") long configId) throws Exception {
        return toAjax(sysOfConfigService.deleteOfConfigById(configId));
    }


    /**
     * 修改配置
     */
    //@SaCheckPermission("system:ofConfig:edit")
    @Log(title = "配置变量", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody SysOfConfig sysOfConfig) throws Exception {
        return toAjax(sysOfConfigService.updateOfConfigEdit(sysOfConfig));
    }


    /**
     * 获取下拉
     */
    @GetMapping("/dropVariablesThe")
    public R<Map<String, Object>> dropVariablesThe(int configType)
    {
        Map<String, Object> ajax = new HashMap<>();
        ajax.put("theDrop", sysOfConfigService.dropVariablesThe(configType));
        return R.ok(ajax);
    }


}
